#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#define N 2005
using namespace std;
int n,m,x,y,tot,head,tail;
int next[N*N*2],point[N],v[N*N*2],ans[N];
bool b[N],pd;
inline int in()
{
    int x=0; char ch=getchar();
    while (ch<'0'||ch>'9') ch=getchar();
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x;
}

void add(int x,int y,int i)
{
    v[i]=y; next[i]=point[x]; point[x]=i;
}

void dfs(int x)
{
    b[x]=true;
    if (x==n){
        pd=true; return;
    }
    for (int i=point[x];i;i=next[i])
      if (!b[v[i]]){
        dfs(v[i]);
        if (pd) return;
      }
}

int main()
{
    n=in(); m=in();
    for (int i=1;i<=m;++i)
    {
        x=in(); y=in();
        add(x,y,i<<1);
        add(y,x,i<<1|1);
    }
    for (int i=2;i<n;++i)
    {
        pd=false;
        memset(b,0,sizeof(b));
        b[i]=true;
        dfs(1);
        if (!pd) ans[++tot]=i;
    }

    printf("%d\n",tot);
    for (int i=1;i<tot;++i)
      printf("%d ",ans[i]);
    printf("%d\n",ans[tot]);
}
